function ExportToExcel(nombre_tabla, titulo) {
	input_box=confirm("¿Exportar los resultados del reporte hacia MS Excel?");
		if (input_box==true) {
			debugger;
			var xlApp = new ActiveXObject("Excel.Application");
			// Silent-mode:
			xlApp.Visible = true;
			xlApp.DisplayAlerts = false;
			var xlBook = xlApp.Workbooks.Add();
			xlBook.worksheets(1).activate;
			var XlSheet = xlBook.activeSheet;
			XlSheet.Name=titulo;
			tabletoexport = document.getElementById(nombre_tabla);
			
			// Store the sheet header names in an array
			var rows = tabletoexport.getElementsByTagName("tr");
			var columns = tabletoexport.getElementsByTagName("th");
			var data = tabletoexport.getElementsByTagName("td");
			
  			// Set Excel Column Headers and formatting from array
			for(i=0;i<columns.length;i++){
	   			XlSheet.cells(1,i+1).value= columns[i].innerText; //XlSheetHeader[i];
	   			XlSheet.cells(1,i+1).font.color="6";
	   			XlSheet.cells(1,i+1).font.bold="true";
	   			XlSheet.cells(1,i+1).interior.colorindex="45";
			}
			
			//run over the dynamic result table and pull out the values and insert into corresponding Excel cells
			var d = 0;
			for (r=2;r<rows.length+1;r++) { // start at row 2 as we've added in headers - so also add in another row!
				for (c=1;c<columns.length+1;c++) {
					XlSheet.cells(r,c).value = data[d].innerText;
					d = d + 1;
				}
			}
			
			//autofit the columns
			XlSheet.columns.autofit;
			
			// Make visible:
			xlApp.visible = true;
			xlApp.DisplayAlerts = true;
			CollectGarbage();
			//xlApp.Quit();
		}
}